package com.ymatou.iapi.marketingmanage.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.marketingmanage.parameter.CancelOrEndPromotionBean;
import com.ymatou.iapi.marketingmanage.parameter.CreateSellerPromotionBean;
import com.ymatou.iapi.marketingmanage.service.CancelOrEndPromotionCall;
import com.ymatou.iapi.trading.operate.parameter.enums.PromotionTypeEnum;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JSellerPromotionCallService;
import com.ymttest.database.mongo.NewSellerPromotionInfoWapper;
/**
*促销活动详情
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CancelOrEndPromotion{
	private static CancelOrEndPromotionBean CancelOrEndPromotionBean;
	private static CancelOrEndPromotionCall CancelOrEndPromotionCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("促销活动详情");
	}

	@Before
	public void caseUp() {
		CancelOrEndPromotionBean=new CancelOrEndPromotionBean();
		CancelOrEndPromotionCall=new CancelOrEndPromotionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(CancelOrEndPromotionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CancelOrEndPromotion_001() {
		Logger.start(true,"取消活动成功");
		try {
			int sellerid=103;
			JSellerPromotionCallService.CancelEnablePromotion(sellerid);
			CreateSellerPromotionBean cspb = JSellerPromotionCallService.initCreateSellerPromotionBean(sellerid, PromotionTypeEnum.DiscountIfAmountEnough);
			int pid=JSellerPromotionCallService.CreateSellerPromotion(cspb);
			CancelOrEndPromotionBean.setPromotionId(pid);
			CancelOrEndPromotionBean.setSellerId(sellerid);
			CancelOrEndPromotionBean.setOperatorType(1);
			CancelOrEndPromotionCall.setData(CancelOrEndPromotionBean);
			CancelOrEndPromotionCall.callService();			
			Logger.verifyEquals("操作成功", CancelOrEndPromotionCall.getString("Msg"), "验证Msg");
			Logger.verifyEquals("200", CancelOrEndPromotionCall.getString("Code"), "验证Code");
			Logger.verifyEquals("0", CancelOrEndPromotionCall.getString("BCode"), "验证BCode");
			JsonObject json = CancelOrEndPromotionCall.getJsonObject().getAsJsonObject("Data");
			Logger.verifyEquals(true, json.get("IsSuccess").getAsBoolean(), "验证IsSuccess");
			Map m=new NewSellerPromotionInfoWapper().getPromotionById(pid);
			Logger.debug(m);
			String em=m.get("em").toString();
			Logger.verifyEquals("3", em, "验证em");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CancelOrEndPromotion_002() {
		Logger.start(true,"提前取消活动成功");
		try {
			int sellerid=103;
			JSellerPromotionCallService.CancelEnablePromotion(sellerid);
			CreateSellerPromotionBean cspb = JSellerPromotionCallService.initCreateSellerPromotionBean(sellerid, PromotionTypeEnum.DiscountIfAmountEnough);
			int pid=JSellerPromotionCallService.CreateSellerPromotion(cspb);
			CancelOrEndPromotionBean.setPromotionId(pid);
			CancelOrEndPromotionBean.setSellerId(sellerid);
			CancelOrEndPromotionBean.setOperatorType(2);
			CancelOrEndPromotionCall.setData(CancelOrEndPromotionBean);
			CancelOrEndPromotionCall.callService();			
			Logger.verifyEquals("操作成功", CancelOrEndPromotionCall.getString("Msg"), "验证Msg");
			Logger.verifyEquals("200", CancelOrEndPromotionCall.getString("Code"), "验证Code");
			Logger.verifyEquals("0", CancelOrEndPromotionCall.getString("BCode"), "验证BCode");
			JsonObject json = CancelOrEndPromotionCall.getJsonObject().getAsJsonObject("Data");
			Logger.verifyEquals(true, json.get("IsSuccess").getAsBoolean(), "验证IsSuccess");
			Map m=new NewSellerPromotionInfoWapper().getPromotionById(pid);
			Logger.debug(m);
			String em=m.get("em").toString();
			Logger.verifyEquals("4", em, "验证em");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_CancelOrEndPromotion_003() {
		Logger.start(false,"不输入sellerid失败");
		try {
			int sellerid=103;
			JSellerPromotionCallService.CancelEnablePromotion(sellerid);
			CreateSellerPromotionBean cspb = JSellerPromotionCallService.initCreateSellerPromotionBean(sellerid, PromotionTypeEnum.DiscountIfAmountEnough);
			int pid=JSellerPromotionCallService.CreateSellerPromotion(cspb);
			CancelOrEndPromotionBean.setPromotionId(pid);
//			CancelOrEndPromotionBean.setSellerId(sellerid);
			CancelOrEndPromotionBean.setOperatorType(2);
			CancelOrEndPromotionCall.setData(CancelOrEndPromotionBean);
			CancelOrEndPromotionCall.callService();		
			Logger.verifyIsContains("错误的请求参数", CancelOrEndPromotionCall.getString("Msg"), "验证Msg");
			Logger.verifyEquals("400", CancelOrEndPromotionCall.getString("Code"), "验证Code");
			Logger.verifyEquals("-1", CancelOrEndPromotionCall.getString("BCode"), "验证BCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CancelOrEndPromotion_004() {
		Logger.start(false,"不输入PromotionId失败");
		try {
			int sellerid=103;
			JSellerPromotionCallService.CancelEnablePromotion(sellerid);
			CreateSellerPromotionBean cspb = JSellerPromotionCallService.initCreateSellerPromotionBean(sellerid, PromotionTypeEnum.DiscountIfAmountEnough);
			int pid=JSellerPromotionCallService.CreateSellerPromotion(cspb);
//			CancelOrEndPromotionBean.setPromotionId(pid);
			CancelOrEndPromotionBean.setSellerId(sellerid);
			CancelOrEndPromotionBean.setOperatorType(2);
			CancelOrEndPromotionCall.setData(CancelOrEndPromotionBean);
			CancelOrEndPromotionCall.callService();				
			Logger.verifyIsContains("无效的促销编号", CancelOrEndPromotionCall.getString("Msg"), "验证Msg");
			Logger.verifyEquals("400", CancelOrEndPromotionCall.getString("Code"), "验证Code");
			Logger.verifyEquals("-1", CancelOrEndPromotionCall.getString("BCode"), "验证BCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CancelOrEndPromotion_005() {
		Logger.start(false,"不输入OperatorType失败");
		try {
			int sellerid=103;
			JSellerPromotionCallService.CancelEnablePromotion(sellerid);
			CreateSellerPromotionBean cspb = JSellerPromotionCallService.initCreateSellerPromotionBean(sellerid, PromotionTypeEnum.DiscountIfAmountEnough);
			int pid=JSellerPromotionCallService.CreateSellerPromotion(cspb);
			CancelOrEndPromotionBean.setPromotionId(pid);
			CancelOrEndPromotionBean.setSellerId(sellerid);
//			CancelOrEndPromotionBean.setOperatorType(2);
			CancelOrEndPromotionCall.setData(CancelOrEndPromotionBean);
			CancelOrEndPromotionCall.callService();				
			Logger.verifyIsContains("无效的操作类型", CancelOrEndPromotionCall.getString("Msg"), "验证Msg");
			Logger.verifyEquals("400", CancelOrEndPromotionCall.getString("Code"), "验证Code");
			Logger.verifyEquals("-1", CancelOrEndPromotionCall.getString("BCode"), "验证BCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CancelOrEndPromotion_006() {
		Logger.start(false,"PromotionId和sellerid不匹配失败");
		try {
			int sellerid=103;
			JSellerPromotionCallService.CancelEnablePromotion(sellerid);
			CreateSellerPromotionBean cspb = JSellerPromotionCallService.initCreateSellerPromotionBean(sellerid, PromotionTypeEnum.DiscountIfAmountEnough);
			int pid=JSellerPromotionCallService.CreateSellerPromotion(cspb);
			CancelOrEndPromotionBean.setPromotionId(pid);
			CancelOrEndPromotionBean.setSellerId(1);
			CancelOrEndPromotionBean.setOperatorType(2);
			CancelOrEndPromotionCall.setData(CancelOrEndPromotionBean);
			CancelOrEndPromotionCall.callService();				
			Logger.verifyIsContains("错误的请求参数", CancelOrEndPromotionCall.getString("Msg"), "验证Msg");
			Logger.verifyEquals("400", CancelOrEndPromotionCall.getString("Code"), "验证Code");
			Logger.verifyEquals("-1", CancelOrEndPromotionCall.getString("BCode"), "验证BCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}